package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.Address;
import com.xinhe.web.request.ServiceCenterQuery;
import com.xinhe.web.service.AddressService;
import com.xinhe.web.service.AliyunService;
import com.xinhe.web.service.ServiceCenterService;
import com.xinhe.web.util.ValidatorUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Api(value = "地址", tags = {"地址"})
@RestController
@RequestMapping(value = {"/address"}, produces = {"application/json;charset=UTF-8"})

public class AddressController {
    @Autowired
    private AddressService addressService;

    @ApiOperation(httpMethod = "GET", value = "分页查询地址")
    @RequestMapping({"/pageAddress"})
    public QueryResults<Address> pageAddress(Long userId,int pageNum, int pageSize) {
        return this.addressService.pageAddress(userId,pageNum,pageSize);
    }
    @ApiOperation(httpMethod = "POST", value = "保存地址")
    @RequestMapping({"/saveAddress"})
    public Result saveAddress(Long id,String name,String telephone,Long provinceId,Long cityId,Long areaId,
                              String detail,Integer isDefault,String province,String city,String area) {//0-否 1-是
        return this.addressService.saveAddress(id, name, telephone, provinceId, cityId, areaId,
                 detail, isDefault, province, city, area);
    }
    @ApiOperation(httpMethod = "POST", value = "设置默认收货地址")
    @RequestMapping({"/saveDefaultAddress"})
    public Result saveDefaultAddress(Long addressId,Integer isdefault) {
        return this.addressService.saveDefaultAddress(addressId,isdefault);
    }
    @ApiOperation(httpMethod = "GET", value = "查询默认收货地址")
    @RequestMapping({"/findDefaultAddress"})
    public Result findDefaultAddress(@RequestParam(required = false) Long userId) {
        return this.addressService.findDefaultAddress(userId);
    }

    @ApiOperation(httpMethod = "GET", value = "删除地址")
    @ApiImplicitParam(name = "addressId", value = "标识", required = true)
    @RequestMapping({"/deleteAddress"})
    public Result deleteAddress(Long addressId) {
        return this.addressService.delete(addressId);
    }
    @ApiOperation(httpMethod = "GET", value = "地址详情")
    @RequestMapping({"/detailAddress"})
    public Result detailAddress(Long addressId) {
        return this.addressService.detailAddress(addressId);
    }
}
